/**
 * 表码翻译指令
 * @Author: huangjq
 * @Date:   2019-04-08
 * @Project jz
 */
import utils from "@/common/utils";
const { ztData } = utils;
export default {
    bind: handler,
    update: handler,
    componentUpdated: handler
};

function handler(el, binding) {
    let params = {};
    let value;
    let keys = Object.keys(binding.value);
    if (keys.length === 0) {
        throw "表码名称不存在";
    } else {
        let key = keys[0];
        params["code"] = key;
        value = binding.value[key];
    }
    ztData.fetchData(
        params,
        function(data) {
            if (data[value]) {
                el.textContent = data[value];
            }
        },
        "codeObj"
    );
}
